/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.unibo.as.HeartsLogic;



/**
 *
 * @author lilith
 */
public class Card 
{
    final String seedCard;
    final String numberCard;
    boolean bIsValid;
    final int nCard;
    final int nSeed;
    
    private final int CARD_A              = 0;
    private final int CARD_K              = 12;
    
    private final int SEED_SPADES         = 0;
    private final int SEED_DIAMONDS       = 1;
    private final int SEED_HEARTS         = 2; 
    private final int SEED_FLOWERS        = 3;

    public Card(String card) 
    {
        bIsValid = true;
        card = card.toUpperCase();
        seedCard = card.substring(0, 1);
        numberCard = card.substring(1, card.length());
        
        nCard = new Integer(numberCard);
       
        if((nCard < CARD_A) && (nCard > CARD_K))
        {
            bIsValid = false;
        }
        
        int nTemp = -1;
        
        if(bIsValid)
        {
            if(seedCard.equalsIgnoreCase(Common.SEED_SPADES))
            {
                nTemp = SEED_SPADES;
            }
            else if(seedCard.equalsIgnoreCase(Common.SEED_DIAMONDS))
            {
                nTemp = SEED_DIAMONDS;
            }
            else if(seedCard.equalsIgnoreCase(Common.SEED_HEARTS))
            {
                nTemp = SEED_HEARTS;
            }
            else if(seedCard.equalsIgnoreCase(Common.SEED_FLOWERS))
            {
                nTemp = SEED_FLOWERS;
            }
            else
            {
                bIsValid = false;
            }
        }
        
        nSeed = nTemp;
    }
    
    public String getCardString()
    {
        String ret = "";
        if(bIsValid)
        {
            ret = seedCard + numberCard;
        }
        return ret; 
    }
    
    public boolean isValid()
    {
        return bIsValid;
    }

    public boolean isEqual(Card card)
    {
        boolean bRet = false;
        if((card.seedCard.equalsIgnoreCase(this.seedCard)) && (card.nCard == this.nCard))
        {
            bRet = true;
        }
        
        return bRet;
    }
}
